﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SocialPlatformSDK.Model;
using SocialPlatformSDK.Services.Util;

namespace SocialPlatformSDK
{
    public class TencentServiceArgument : ServiceArgument
    {
        public TencentServiceArgument()
        {
            this.Format = DataFormat.Json;
        }
        
        /// <summary>
        /// 获取或设置分页标识.
        /// </summary>
        /// <remarks>
        /// 0：第一页，1：向下翻页，2：向上翻页.
        /// </remarks>
        public int PageFlag { get; set; }

        /// <summary>
        /// 获取或设置本页起始时间
        /// </summary>
        /// <remarks>
        /// 第一页：填0，向上翻页：填上一次请求返回的第一条记录时间，向下翻页：
        /// 填上一次请求返回的最后一条记录时间.
        /// </remarks>
        public int PageTime { get; set; }

        /// <summary>
        /// 获取或设置每次请求记录的条数 .
        /// </summary>
        public int Reqnum { get; set; }

        /// <summary>
        /// 获取或设置用户/微博 Id.
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// 获取或设置拉取类型 .
        /// </summary>
        /// <remarks>
        /// 0x1 原创发表 
        /// 0x2 转载 
        /// 0x8 回复 
        /// 0x10 空回 
        /// 0x20 提及 
        /// 0x40 点评 
        /// 如需拉取多个类型请使用|，如(0x1|0x2)得到3，则type=3即可，填零表示拉取所有类型 .
        /// </remarks>
        public int Type { get; set; }

        /// <summary>
        /// 获取或设置内容过滤.
        /// </summary>
        /// <remarks>
        /// 0-表示所有类型，1-带文本，2-带链接，4-图片，8-带视频，0x10-带音频.
        /// </remarks>
        public ContentType ContentType { get; set; }

        /// <summary>
        /// 获取或设置权限标识。1－表示只显示我发表的，默认填零.
        /// </summary>
        public int  AccessLevel { get; set; }

        /// <summary>
        /// 获取或设置你需要读取的用户的用户名（可选）. 
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 获取或设置你需要读取的用户名列表，中间用_隔开.
        /// </summary>
        public string FOpenIds { get; set; }

        /// <summary>
        /// 获取或设置你需要读取的用户的openid（可选）.
        /// </summary>
        public string FOpenId { get; set; }

        /// <summary>
        /// 获取或设置起始位置.
        /// </summary>
        /// <remarks>
        /// 第一页填0，继续向下翻页：填【reqnum*（page-1）】.
        /// </remarks>
        public int StartIndex  { get; set; }

        /// <summary>
        /// 获取或设置微博内容.
        /// </summary>
        public string Content { get; set; }

        /// <summary>
        /// 获取或设置需要上传的 Pic.
        /// </summary>
        public UploadPic Pic { get; set; }

        /// <summary>
        /// 获取或设置返回数据的格式.
        /// </summary>
        /// <remarks>
        /// json或xml, 但暂时只提供Json方式.
        /// </remarks>
        public DataFormat Format { get; set; }


        public AccessToken AccessToken { get; set; }

        public string Oauth_Consumer_Key { get; set; }

        public string OpenId { get; set; }

        public string Oauth_Version = "2.a";

        public string ClientIp {get;set;}

        public Dictionary<string, object> ParseArg()
        {
            Dictionary<string, object> args = new Dictionary<string, object>();

            if (!string.IsNullOrEmpty(this.Id))
            {
                args.Add("id", this.Id);
            }

            if (!string.IsNullOrEmpty(this.Name))
            {
                args.Add("name", this.Name);
            }

            if (!string.IsNullOrEmpty(this.FOpenIds))
            {
                args.Add("fopenids", this.FOpenIds);
            }

            if (this.PageFlag != 0)
            {
                args.Add("pageflag", this.PageFlag);
            }

            if (this.PageTime != 0)
            {
                args.Add("pagetime", this.PageTime);
            }

            if (this.Reqnum != 0)
            {
                args.Add("reqnum", this.Reqnum);
            }

            if (this.Type != 0)
            {
                args.Add("type", this.Type);
            }

            if (this.ContentType != 0)
            {
                args.Add("contenttype", this.ContentType);
            }

            if (this.StartIndex != 0)
            {
                args.Add("startindex", this.StartIndex);
            }

            if (!string.IsNullOrEmpty(this.Content))
            {
                args.Add("content", this.Content);
            }

            if (!string.IsNullOrEmpty(this.FOpenId))
            {
                args.Add("fopenid", this.FOpenId);
            }

            if (null != this.Pic)
            {
                args.Add("pic", this.Pic);
            }

            switch (this.Format)
            {
                case DataFormat.Json:
                    args.Add("format", "json");
                    break;
                case DataFormat.Xml:
                    args.Add("format", "xml");
                    break;
                default:
                    break;
            }

            if (!string.IsNullOrEmpty(this.AccessToken.AccesssToken))
            {
                args.Add("access_token", this.AccessToken.AccesssToken);
            }

            if (!string.IsNullOrEmpty(this.Oauth_Consumer_Key))
            {
                args.Add("oauth_consumer_key", this.Oauth_Consumer_Key);
            }

            if (!string.IsNullOrEmpty(this.OpenId))
            {
                args.Add("openid", this.OpenId);
            }

            if (!string.IsNullOrEmpty(this.ClientIp))
            {
                args.Add("clientip", this.ClientIp);
            }
            args.Add("oauth_version", Oauth_Version);
            return args;
        }
    }
}
